package com.ruoyi.crm.controller;

import java.util.List;

import com.ruoyi.crm.domain.CrmNiche;
import com.ruoyi.crm.service.ICrmNicheService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商机Controller
 * 
 * @author ruoyi
 * @date 2023-03-30
 */
@RestController
@RequestMapping("/niche")
public class CrmNicheController extends BaseController
{
    @Autowired
    private ICrmNicheService crmNicheService;

    /**
     * 查询商机列表
     */
    @PreAuthorize("@ss.hasPermi('system:niche:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmNiche crmNiche)
    {
        startPage();
        List<CrmNiche> list = crmNicheService.selectCrmNicheList(crmNiche);
        return getDataTable(list);
    }

    /**
     * 导出商机列表
     */
    @PreAuthorize("@ss.hasPermi('system:niche:export')")
    @Log(title = "商机", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmNiche crmNiche)
    {
        List<CrmNiche> list = crmNicheService.selectCrmNicheList(crmNiche);
        ExcelUtil<CrmNiche> util = new ExcelUtil<CrmNiche>(CrmNiche.class);
        return util.exportExcel(list, "niche");
    }

    /**
     * 获取商机详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:niche:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmNicheService.selectCrmNicheById(id));
    }

    /**
     * 新增商机
     */
    @PreAuthorize("@ss.hasPermi('system:niche:add')")
    @Log(title = "商机", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(/*@RequestBody */CrmNiche crmNiche)
    {
        return toAjax(crmNicheService.insertCrmNiche(crmNiche));
    }

    /**
     * 修改商机
     */
    @PreAuthorize("@ss.hasPermi('system:niche:edit')")
    @Log(title = "商机", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(/*@RequestBody*/ CrmNiche crmNiche)
    {
        return toAjax(crmNicheService.updateCrmNiche(crmNiche));
    }

    /**
     * 删除商机
     */
    @PreAuthorize("@ss.hasPermi('system:niche:remove')")
    @Log(title = "商机", businessType = BusinessType.DELETE)
	@DeleteMapping("/del")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmNicheService.deleteCrmNicheByIds(ids));
    }
}
